home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Base / sa / flt < prev    next >
Text File  |  1996-07-18  |  20KB  |  662 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  3. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  4. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  5. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  6. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  7. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  8.  
  9. immutable class FLT < $NUMBER{FLT}, $HASH, $FMT is
  10.    -- IEEE 754-1984 "single" format 32-bit floating point.
  11.    -- Most of these functions presently just call the FLTD versions
  12.    -- because of C double/float calling convention weirdness; this
  13.    -- is the most portable way.
  14.    include COMPARABLE;
  15.  
  16.    
  17.    plus(f:SAME):SAME is        
  18.       -- The sum of self and `f'. Built-in.
  19.       builtin FLT_PLUS;
  20.    end;
  21.  
  22.    minus(f:SAME):SAME is    
  23.       -- The difference between self and `f'. Built-in.     
  24.       builtin FLT_MINUS;
  25.    end;   
  26.     
  27.    negate:SAME is        
  28.       -- The negation of self. Same as zero minus self,
  29.       -- except that IEEE does funny things for the sign bit and
  30.       -- different rounding modes.
  31.       builtin FLT_NEGATE;
  32.    end;
  33.  
  34.    times(f:SAME):SAME is    
  35.       -- The signed product of self and `f'. Built-in.
  36.       builtin FLT_TIMES;
  37.    end;   
  38.     
  39.    div(f:SAME):SAME is        
  40.       -- The quotient of self and `f'. Built-in.
  41.       builtin FLT_DIV;
  42.    end;   
  43.     
  44.    is_eq(f:SAME):BOOL is    
  45.       -- True if self and `f' represent the same value.  Built-in.
  46.       builtin FLT_IS_EQ;
  47.    end;
  48.  
  49.    is_lt(f:SAME):BOOL is    -- True if self is less than `f'. Built-in.
  50.       builtin FLT_IS_LT;
  51.    end;   
  52.  
  53.    is_bet(l,u:SAME):BOOL is
  54.       -- Another name for `is_between'.
  55.       return self.is_between(l,u)
  56.    end;
  57.     
  58.    is_between(l,u:SAME):BOOL is
  59.       -- True if self between l and u.
  60.       return (l<=self and self<=u) or (u<=self and self<=l) end;
  61.  
  62.    is_within(tolerance,val:SAME):BOOL is
  63.       return (self-val).abs<=tolerance;
  64.    end;
  65.  
  66.    hash:INT is
  67.       -- A lousy hash function, can someone suggest better?
  68.       return truncate.int.hash;
  69.    end;
  70.  
  71.    is_finite:BOOL is        -- returns true if zero, subnormal or normal.
  72.       return RUNTIME::ir_finite(self);
  73.    end;
  74.  
  75.    is_inf:BOOL is        -- returns true if infinite
  76.       return RUNTIME::ir_isinf(self);
  77.    end;
  78.  
  79.    is_nan:BOOL is        
  80.       -- returns true if NaN.  See comment at "is_nil".
  81.       return ~(self=self);
  82.    end;
  83.  
  84.    is_normal:BOOL is        -- returns true if normal
  85.       builtin IR_ISNORMAL;
  86.    end;
  87.  
  88.    is_subnormal:BOOL is        -- returns true if subnormal
  89.       builtin IR_ISSUBNORMAL;
  90.    end;
  91.  
  92.    is_zero:BOOL is        -- returns true is zero
  93.       builtin IR_ISZERO;
  94.    end;
  95.  
  96.    signbit_set:BOOL is        -- returns true if sign bit of self is set
  97.       builtin IR_SIGNBIT;
  98.    end;
  99.  
  100.    unbiased_exponent:INT is
  101.       -- return unbiased exponent of self as an INT;
  102.       -- for zero this is INT::maxint.negate, for an
  103.       -- infinite it is INT::maxint.  If subnormal,
  104.       -- normalization occurs first.
  105.       builtin IR_ILOGB;
  106.    end;
  107.  
  108.    copysign(y:SAME):SAME is
  109.       -- return self with the sign bit set to the same as y's sign bit.
  110.       builtin R_COPYSIGN;
  111.    end;
  112.  
  113.    nextup:SAME is        -- return next representable number from self.
  114.       builtin R_NEXTUP;
  115.    end;
  116.  
  117.    nextdown:SAME is        
  118.       -- return previous representable number from self.
  119.       builtin R_NEXTDOWN;
  120.    end;
  121.  
  122.    remainder(y:SAME):SAME is
  123.       -- x.remainder(y) and x.mod(y) return a remainder of x with respect
  124.       -- to y; that is, the result r is one of the numbers that differ from
  125.       -- x by an integral multiple of y.  Thus (x-r)/y  is an integral
  126.       -- value, even though it might exceed INT::maxint if it were
  127.       -- explicitly computed as an INT.  Both functions return one  of the
  128.       -- two such r smallest in magnitude.  remainder(x,y) is the operation
  129.       -- specified in ANSI/IEEE Std 754-1985; the result of x.mod(y) may
  130.       -- differ from remainder's result by +-y.  The magnitude of
  131.       -- remainder's result can not exceed half that of y; its sign might
  132.       -- not agree with either x or y.  The magnitude of mod's result is
  133.       -- less than that of y; its sign agrees with that of x.  Neither
  134.       -- function will raise an exception as long as both arguments are
  135.       -- normal or subnormal.  x.remainder(0), x.mod(0), infinity.remainder(y),
  136.       -- and infinity.mod(y) are invalid operations that produce a NaN.
  137.  
  138.       builtin R_REMAINDER;
  139.    end;
  140.  
  141.    mod(y:SAME):SAME is    -- See comment at `remainder'.
  142.       builtin R_FMOD;
  143.    end;
  144.  
  145.    scale_by(n:INT):SAME is
  146.       -- return x*2.pow(n) computed by exponent manipulation rather
  147.       -- than by actually performing an exponentiation or a multiplication.
  148.       --
  149.       --    1 <= x.abs.scale_by(-x.unbiased_exponent) < 2 
  150.       --
  151.       -- for every x except 0, infinity, and NaN.
  152.       builtin R_SCALBN;
  153.    end;
  154.  
  155.    bessel_j0:SAME is
  156.       -- Bessel functions of the first and second kinds.  y0, y1 and yn have
  157.       -- logarithmic singularities at the origin, so they treat zero and
  158.       -- negative arguments the way log does.
  159.       builtin R_J0;
  160.    end;
  161.  
  162.    bessel_j1:SAME is
  163.       -- See comment at `bessel_j0'.
  164.       builtin R_J1;
  165.    end;
  166.  
  167.    bessel_jn(n:INT):SAME is
  168.       -- See comment at `bessel_j0'.
  169.       builtin R_JN;
  170.    end;
  171.  
  172.    bessel_y0:SAME is
  173.       -- See comment at `bessel_j0'.
  174.       builtin R_Y0;
  175.    end;
  176.  
  177.    bessel_y1:SAME is
  178.       -- See comment at `bessel_j0'.
  179.       builtin R_Y1;
  180.    end;
  181.  
  182.    bessel_yn(n:INT):SAME is
  183.       -- See comment at `bessel_j0'.
  184.       builtin R_YN;
  185.    end;
  186.  
  187.    erf:SAME is
  188.       -- error function:
  189.       --   x.erf = (1/sqrt(pi))*integrate(0,x,exp(-t^2)dt)
  190.       builtin R_ERF;
  191.    end;
  192.  
  193.    one_minus_erf:SAME is
  194.       -- 1.0-self.erf, but computed in a way to avoid
  195.       -- cancellation for large self.
  196.       builtin R_ERFC;
  197.    end;
  198.  
  199.    exp:SAME is            -- The exponential e^self.
  200.       -- Exponential, logarithm, power functions.  All these functions handle
  201.       -- exceptional arguments in the spirit of IEEE 754-1985.  So:
  202.       --    0.log is -infinity with a division by zero exception
  203.       --    For x<0, including -infinity, x.log is a quiet NaN with an
  204.       --    invalid op exception
  205.       --    For x=+infinity or a quiet NaN, x.log is x without exception
  206.       --    For a signaling NaN, x.log is a quiet NaN with 
  207.       --    an invalid op exception
  208.       --    1.log is zero without exception
  209.       -- For any other positive x, x.log is a normalized number with an
  210.       -- inexact exception.
  211.  
  212.       builtin R_EXP;
  213.    end;
  214.     
  215.    exp_minus_one:SAME is    -- e^self-1.0, accurate even for tiny self.
  216.       -- See comment at `exp'.
  217.       builtin R_EXPM1;
  218.    end;
  219.  
  220.    exp2:SAME is            -- 2^self
  221.       -- See comment at `exp'.
  222.       builtin R_EXP2;
  223.    end;
  224.  
  225.    exp10:SAME is        -- 10^self
  226.       -- See comment at `exp'.
  227.       builtin R_EXP10;
  228.    end;
  229.     
  230.    log:SAME is            -- The natural logarithm of self.
  231.       -- See comment at `exp'.
  232.       builtin R_LOG;
  233.    end;
  234.  
  235.    plus_one_log:SAME is        -- (self+1).log, accurate even for tiny self.
  236.       -- See comment at `exp'.
  237.       builtin R_LOG1P;
  238.    end;
  239.  
  240.    log2:SAME is            -- The logarithm base two of self.
  241.       -- See comment at `exp'.
  242.       return self.log*log2_e;
  243.    end;
  244.  
  245.    log10:SAME is        -- The logarithm base ten of self.
  246.       -- See comment at `exp'.
  247.       builtin R_LOG10;
  248.    end;
  249.  
  250.    pow(arg:SAME):SAME is
  251.       -- self raised to the arg'th power.  x.pow(0.0)=1.0 for all x.
  252.       -- See comment at `exp'.
  253.       builtin R_POW;
  254.    end;
  255.  
  256.    acosh:SAME is        -- The inverse hyperbolic cosine of self.
  257.       -- The hyperbolic functions handle exceptional arguments in the
  258.       -- spirit of IEEE 754-1985.  So:
  259.       --    sinh and cosh return +-infinity on overflow
  260.       --    acosh returns a NaN if its argument is less than 1.0
  261.       --    atanh returns a NaN if its argument has an absolute value >1.0
  262.       builtin R_ACOSH;
  263.    end;
  264.     
  265.    cosh:SAME is            -- The hyperbolic cosine of self.
  266.       -- See comment at `acosh'.
  267.       builtin R_COSH;
  268.    end;
  269.     
  270.    sinh:SAME is            -- The hyperbolic sine of self.
  271.       -- See comment at `acosh'.
  272.       builtin R_SINH;
  273.    end;
  274.     
  275.    tanh:SAME is            -- The hyperbolic tangent of self.
  276.       -- See comment at `acosh'.
  277.       builtin R_TANH;
  278.    end;
  279.  
  280.    asinh:SAME is        -- The inverse hyperbolic sine of self.
  281.       -- See comment at `acosh'.
  282.       builtin R_ASINH;
  283.    end;
  284.     
  285.    atanh:SAME is        -- The inverse hyperbolic tangent of self.
  286.       -- See comment at `acosh'.
  287.       builtin R_ATANH;
  288.    end;
  289.  
  290.  
  291.    hypot(arg:SAME):SAME is
  292.       -- sqrt(self*self+arg*arg), taking precautions against unwarranted
  293.       -- IEEE exceptions.  +-infinity.hypot(arg) is +infinity for any arg,
  294.       -- even a NaN, and is exceptional only for a signaling NaN.
  295.       builtin R_HYPOT;
  296.    end;
  297.  
  298.    acos:SAME is            
  299.       -- The arc sine of self in the range [0.0, pi].
  300.       -- The trigonometric functions handle exceptional arguments
  301.       -- in the spirit of IEEE 754-1985.  So:
  302.       --    +-infinity.sin, +-infinity.cos, +-infinity.tan return NaN
  303.       --    x.asin and x.acos with x.abs>1 return NaN
  304.       -- sinpi etc. are similar except they compute
  305.       -- self.sinpi=(self*pi).sin avoiding range-reduction issues
  306.       -- because their definition permits range reduction that is fast
  307.       -- and exact for all self.  The corresponding inverse functions
  308.       -- compute asinpi(x).
  309.       builtin R_ACOS;
  310.    end;
  311.  
  312.    sin:SAME is             -- See comment at `acos'.
  313.       builtin R_SIN;
  314.    end;
  315.  
  316.    cos:SAME is             -- See comment at `acos'.
  317.       builtin R_COS;
  318.    end;
  319.  
  320.    sincos(out s:FLT,out c:FLT) is
  321.       -- Simultaneous computation of self.sin and self.cos.  This is faster
  322.       -- than independently computing them.
  323.       -- See comment at `acos'.
  324.       builtin SINCOS;
  325.    end;
  326.  
  327.    tan:SAME is
  328.       -- See comment at `acos'.
  329.       builtin R_TAN;
  330.    end;
  331.  
  332.    asin:SAME is            
  333.       -- The arc sine of self in the range [-pi/2, pi/2]
  334.       -- See comment at `acos'.
  335.       builtin R_ASIN;
  336.    end;
  337.  
  338.    atan:SAME is            
  339.       -- The arc tangent of self in the range [-pi/2, pi/2].
  340.       -- See comment at `acos'.
  341.       builtin R_ATAN;
  342.    end;
  343.  
  344.    atan2(arg:SAME):SAME is
  345.       -- The arc tangent of self divided by arg in the range [-pi/2, pi/2].
  346.       -- It chooses the quadrant specified by (self, arg).
  347.       -- See comment at `acos'.
  348.       builtin R_ATAN2;
  349.    end;
  350.     
  351.    sinpi:SAME is
  352.       -- See comment at `acos'.
  353.       builtin R_SINPI;
  354.    end;
  355.     
  356.    cospi:SAME is
  357.       -- See comment at `acos'.
  358.       builtin R_COSPI;
  359.    end;
  360.     
  361.    sincospi(out a:FLT,out b:FLT) is
  362.       -- Simultaneous computation of self.sinpi and self.cospi.  Faster
  363.       -- than independently computing them.
  364.       -- See comment at `acos'.
  365.       builtin SINCOSPI;
  366.    end;
  367.     
  368.    tanpi:SAME is
  369.       -- See comment at `acos'.
  370.       builtin R_TANPI;
  371.    end;
  372.     
  373.    asinpi:SAME is    
  374.       -- The arc sine of self*pi in the range [-pi/2, pi/2]
  375.       -- See comment at `acos'.
  376.       builtin R_ASINPI;
  377.    end;
  378.     
  379.    acospi:SAME is        
  380.       -- The arc sine of self*pi in the range [0.0, pi]
  381.       -- See comment at `acos'.
  382.       builtin R_ACOSPI;
  383.    end;
  384.     
  385.    atanpi:SAME is        
  386.       -- The arc tangent of self*pi in the range [-pi/2, pi/2].
  387.       -- See comment at `acos'.
  388.       builtin R_ATANPI;
  389.    end;
  390.  
  391.    atan2pi(arg:SAME):SAME is
  392.       -- The arc tangent of self*pi divided by arg in the range [-pi/2, pi/2].
  393.       -- It chooses the quadrant specified by (self, arg).
  394.       -- See comment at `acos'.
  395.       builtin R_ATAN2PI;
  396.    end;
  397.     
  398.    abs:SAME is            -- The absolute value of self.
  399.       builtin R_FABS;
  400.    end;
  401.     
  402.    sign:SAME is    
  403.       -- -1.0, 0.0, or 1.0, depending whether the sign of self is
  404.       -- negative, zero, or positive.
  405.       if self<0.0 then return -1.0;
  406.       elsif self>0.0 then return 1.0;
  407.       else return 0.0;
  408.       end;
  409.    end;
  410.  
  411.    signum:SAME is return sign end; -- Another name for `sign'.
  412.  
  413.    log_gamma:SAME is
  414.       -- log gamma function.  x.ln_gamma=x.gamma.abs.log
  415.       builtin R_LGAMMA;
  416.    end;
  417.     
  418.    gamma:SAME is
  419.       -- gamma function.
  420.       if self>0.0 then return log_gamma.exp;
  421.       elsif integral then return 0.0;
  422.       elsif abs.floor.int.is_even then return (-log_gamma).exp;
  423.       else return log_gamma.exp;
  424.       end;
  425.    end;
  426.     
  427.    sqrt:SAME is            -- The square root of self.
  428.       builtin R_SQRT;
  429.    end;
  430.     
  431.    square:SAME is        -- The square of self.
  432.       return self*self;
  433.    end;
  434.     
  435.    cube_root:SAME is        -- The cube root of self.
  436.       builtin R_CBRT;
  437.    end;
  438.     
  439.    cube:SAME is            -- The cube of self.
  440.       return self*self*self;
  441.    end;
  442.  
  443.    max(arg:SAME):SAME is    -- The larger of self and arg.
  444.       -- Caution: may not work as one expects if an argument is NaN.
  445.       if self<arg then return arg; else return self; end;
  446.    end;
  447.     
  448.    min(arg:SAME):SAME is    -- The smaller of self and arg.
  449.       -- Caution: may not work as one expects if an argument is NaN.
  450.       if self<arg then return self; else return arg; end;
  451.    end;
  452.     
  453.    at_least(arg:SAME):SAME is return self.max(arg) end; -- Same as `self.max(arg)'
  454.    at_most(arg:SAME):SAME is return self.min(arg) end; -- Same as `self.min(arg)'
  455.     
  456.    str:STR is 
  457.       -- A string version of self. 
  458.       fbuf:FSTR:=#(30);  -- This is poor, but makes it reentrant.
  459.              -- The other str methods work this way too
  460.              -- (they used to use a shared buffer.)
  461.       -- if ((void(fbuf)) or (fbuf.size < 30)) then fbuf := #FSTR(30) end;
  462.       fstr ::= str_in(fbuf);
  463.       return(fstr.str); end;
  464.  
  465.    str(prec:INT):STR is 
  466.       -- A string version of self with arg digits of precision.
  467.       des_sz ::= prec+10;
  468.       fbuf:FSTR:=#(des_sz); -- See comment in `str'.
  469.       -- if ((void(fbuf)) or (fbuf.size < des_sz)) then fbuf:=#FSTR(des_sz) end;
  470.       fstr ::= str_in(fbuf,prec);
  471.       return(fstr.str);  end;
  472.  
  473.    str_in(arg:FSTR):FSTR is 
  474.       store_in: FSTR;
  475.       if (arg.size >= 30) then store_in := arg;
  476.       else store_in := #FSTR(30) end;
  477.       sz ::= store_into(store_in); 
  478.       store_in.loc := sz;
  479.       return(store_in); end;
  480.  
  481.    str_in(arg: FSTR, prec: INT): FSTR is
  482.       store_in: FSTR;
  483.       des_sz ::= prec+10;
  484.       if (arg.size >= des_sz) then store_in := arg;
  485.       else store_in := #FSTR(des_sz) end;
  486.       sz ::= store_into_prec(prec, store_in); 
  487.       store_in.loc := sz;
  488.       return(store_in);  end;
  489.  
  490.    private store_into(s:FSTR):INT is
  491.       -- Store the acsii representation into s.  Built-in.
  492.       builtin FLT_STORE_INTO;
  493.    end;
  494.  
  495.    private store_into_prec(p:INT,s:FSTR):INT is
  496.       -- Store the acsii representation into s with precision p.  Built-in.
  497.       builtin FLT_STORE_PREC;
  498.    end;
  499.  
  500.    fmt( f:STR ): STR is
  501.       -- Return a nicely formatted ascii representation of the number.
  502.       -- See the separate documentation on FMT for a full description.
  503.       return BASE_FORMAT::fmt_flt( self, f )
  504.    end;
  505.    
  506.    create (s: STR): SAME is
  507.       builtin ATOF;
  508.    end;
  509.  
  510.    create(f:INT):SAME is return f.flt end;
  511.    create(f:INTI):SAME is return f.flt end;
  512.    create(f:FLT):SAME is return f end;
  513.    create(f:FLTD):SAME is return f.flt end;
  514.    
  515.    --    create(f:FLTX):SAME is return f.flt end;
  516.    --    create(f:FLTDX):SAME is return f.flt end;
  517.    --    create(f:FLTI):SAME is return f.flt end;
  518.     
  519.    integral:BOOL is
  520.       -- Another name for `is_integral'.
  521.       return self.is_integral
  522.    end;
  523.     
  524.    is_integral:BOOL is
  525.       -- Return true if self is integral.
  526.       return self=truncate;
  527.    end;
  528.      
  529.    int:INT is
  530.       -- INT version of self.  It is an error if self is not integral.
  531.       -- Use truncate, floor, ceiling, or round to achieve this.
  532.       -- Built-in.
  533.       builtin FLT_INT;
  534.    end;
  535.     
  536.    inti:INTI is return #INTI(self) end; -- Conversion to INTI.
  537.     
  538.    flt:FLT is return self end; -- Conversion to FLT (identity operation)
  539.     
  540.    fltd:FLTD is
  541.       -- An FLTD version of self.  Built-in.
  542.       builtin FLT_FLTD; end;
  543.  
  544.    get_representation(out sign:BOOL,out exp: INT,out mantissa: INT)
  545.     -- Get the data representing te flt. (endian independant)
  546.    is
  547.       builtin FLT_GET_REP;
  548.    end;
  549.      
  550.    truncate:SAME is        -- The nearest integer toward zero.  Built-in.
  551.       builtin FLT_TRUNCATE;
  552.    end;
  553.     
  554.    floor:SAME is        -- The largest integer not greater than self.
  555.       builtin R_FLOOR;
  556.       -- return RUNTIME::r_floor(self);
  557.    end;
  558.     
  559.    ceiling:SAME is        -- The smallest integer not less than self.
  560.       builtin R_CEIL;
  561.       -- return RUNTIME::r_ceil(self);
  562.    end;
  563.     
  564.    round:SAME is        -- The closest integer to self.
  565.       builtin FLT_ROUND;
  566.    end;
  567.  
  568.    const pi:SAME:=FLTD::pi.flt; -- An approximation of the mathematical value "pi".
  569.  
  570.    const e:SAME:=FLTD::e.flt; -- An approximation of the base of the natural logarithms "e".
  571.  
  572.    const sqrt_2:SAME:=FLTD::sqrt_2.flt; -- Approximation of 2.sqrt.
  573.    const log_2:SAME:=FLTD::log_2.flt; -- Approximation of 2.log. 
  574.    const log2_e:SAME:=FLTD::log2_e.flt; -- Approximation of e.log2.
  575.    const log10_e:SAME:=FLTD::log10_e.flt; -- Approximation of e.log10.
  576.    const log_10:SAME:=FLTD::log_10.flt; -- Approximation of 10.log. 
  577.    const half_pi:SAME:=FLTD::half_pi.flt; -- Approximation of pi/2. 
  578.    const quarter_pi:SAME:=FLTD::quarter_pi.flt; -- Approximation of pi/4.
  579.    const inv_sqrt_2:SAME:=FLTD::inv_sqrt_2.flt; -- Approximation of 1/(2.sqrt).
  580.    const inv_pi:SAME:=FLTD::inv_pi.flt; -- Approximation of 1/pi. 
  581.    const double_inv_pi:SAME:=FLTD::double_inv_pi.flt; -- Approximation of 2/pi
  582.    const double_sqrt_pi:SAME:=FLTD::double_sqrt_pi.flt; 
  583.    -- Approximation of 2*(pi.sqrt).
  584.  
  585.  
  586.    nil:SAME is
  587.       -- The value to be used to represent no element in sets.
  588.       return signaling_NaN(0);
  589.    end;
  590.    
  591.    is_nil:BOOL is
  592.       return ~(self=self);
  593.       -- Blame IEEE arithmetic for this.  I know how awful it looks.
  594.       -- It works because NaN is the only value which won't compare
  595.       -- with anything.
  596.    end;
  597.  
  598.    signaling_NaN(sig:INT):SAME is
  599.       -- IEEE signalling NaN.  `sig' is the significand (presently unused).
  600.       builtin R_SIGNALING_NAN;
  601.    end;
  602.  
  603.    quiet_NaN(sig:INT):SAME is 
  604.       -- IEEE quiet NaN.  `sig' is the significand (presently unused).
  605.       builtin R_QUIET_NAN;
  606.    end;
  607.  
  608.    infinity:SAME is        -- IEEE Infinity.
  609.       builtin R_INFINITY;
  610.    end;
  611.  
  612.    const zero:SAME := 0.0;               -- See $NUMBER.
  613.    const one: SAME := 1.0;
  614.    maxval:SAME is return infinity; end;  -- Maximal value; see $NUMBER.
  615.    minval:SAME is return -infinity; end; -- Minimal value; see $NUMBER.
  616.     
  617.    const epsilon:SAME:=1.19209290e-07; -- The minimum x>0.0 such that 1.0+x/=x. 
  618.     
  619.    const digits:INT:=6;        -- The number of decimal digits of precision.
  620.  
  621.    const mantissa_bits:INT:=24; -- The number of bits in the significand, including an implied bit.
  622.     
  623.    min_normal:SAME is        -- The smallest normalized positive number.
  624.       builtin MIN_NORMAL;
  625.    end;
  626.  
  627.    max_normal:SAME is        -- The largest normalized positive number.
  628.       builtin MAX_NORMAL;
  629.    end;
  630.  
  631.    min_subnormal:SAME is    -- The smallest subnormal positive number.
  632.       builtin MIN_SUBNORMAL;
  633.    end;
  634.  
  635.    max_subnormal:SAME is    -- The largest subnormal positive number.
  636.       builtin MAX_SUBNORMAL;
  637.    end;
  638.     
  639.    const min_exp:INT:=-125;
  640.    -- The minimum negative integer x such that b^(x-1) is in the range
  641.    -- of normalized floating point numbers.
  642.  
  643.    const min_exp10:INT:=-37;
  644.    -- The minimum x such that 10^x is in the range of normalized
  645.    -- floating point numbers.
  646.     
  647.    const max_exp:INT:=128; -- The maximum allowable exponent.
  648.     
  649.    const max_exp10:INT:=38;-- The maximum x such that 10^x is within range.
  650.  
  651.    sum!(i:SAME):SAME is
  652.       -- Yields the sum of all previous values of `i'.
  653.       r::=0.0; loop r:=r+i; yield r end 
  654.    end;
  655.     
  656.    product!(i:SAME):SAME is
  657.       -- Yields the product of all previous values of `i'.
  658.       r::=1.0; loop r:=r*i; yield r end 
  659.    end;
  660.  
  661. end; -- class FLT
  662.